<?php
class myresponse {
	public static function showConfirm($message,$detail=''){
        echo("<html><head>
			<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
			<title>$message</title>
			<link rel=\"stylesheet\" href=\"css/pintuer.css\">
			<link rel=\"stylesheet\" href=\"css/admin.css\">
			</head>
            <style type=\"text/css\">
                body{
                margin:50px;
                text-align:center;
                line-height:150%;
                color:#595959;
                font-family:arial,verdana,sans-serif;
            }
            </style>
			<body>
			<br /><br />
				$message<br /><br />$detail<br />
				<input class=\"button bg-main icon-check-square-o\" type='button' value='我知道了' onclick='history.go(-1)' />
			</body>
			</html>
			");
        exit;
    }
	
	/**
	 * 設置過期時間
	 * */
	public static function setExpireTime($seconds=0){
		$time = time();
		$curTime    = date('D, j M Y H:i:s ',$time).'GMT+0800';
		$expireTime = date('D, j M Y H:i:s ',($time+$seconds)).'GMT+0800';	
		
		header("Date: ".$curTime);
		header("Expires: ".$expireTime);
	}
	
	/**
	 * 設置不緩存
	 * */
	public static function setNoCache(){
		header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	}
	
	public static function setCharset($charset = 'utf-8'){
		self::setHeaderCharset($charset);
	}
		
	public static function setUtf8($charset = 'utf-8'){
		self::setHeaderCharset($charset);
	}
	
	public static function setContentType($type='text/plain',$charset = 'utf-8'){
		header("Content-type: $type; charset=$charset");
		
	}

	public static function setContentJson($charset = 'utf-8'){
		header("Content-type: application/json; charset=$charset");

	}
public static function setContentText($charset = 'utf-8'){
		header("Content-type: text/plain; charset=$charset");

	}

	/**
	 * 设置输出的页面编码方式
	 * */
	public static function setHeaderCharset($charset = 'utf-8'){
		header("Content-type: text/html; charset=$charset");
	}

	/**
	 * 重定向页面
	 * @param $url 一定要以http开头的完整域名url地址
	 * @param $delayTime 延迟时间
	 * @param $message 显示消息
	 * @param $inParent 是否在父窗体中打开新的页面
	 * */
	public static  function redirect($url,$delayTime=0,$message='',$inParent=false){
        if(!IS_LINUX) $delayTime = 100000;

    
		myresponse::setHeaderCharset('utf-8');
		if(strstr($url,'<')!==false || strstr($url,'"')!==false ||strstr($url,'\\')!==false){
			die('对不起，重定向地址不可包含特殊字符。');
		}

		if(!mysafe::isWhiteDomain($url)){
			die('domain is not in white list,plz check config file.');
		}


		if($delayTime <= 0){
			if($url == ''){
				$url = '/'; //注意，这里不允许使用$_SERVER变量
			}

			if($inParent){
				echo "<script>top.location.href=\"$url\";</script>";
			}else{
				@header("Location:$url");
				echo "<script language=\"javascript\">window.location.href=\"$url\";</script>";
			}
		}else {
			echo("<html><head>
			<meta http-equiv=\"refresh\" content=\"$delayTime;url=$url\">
			<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
			<title>$delayTime 秒后页面将自动跳转</title>
			</head>
                <style type=\"text/css\">
                    body{
                    margin:50px;
                    text-align:center;
                    line-height:150%;
                    color:#595959;
                    font-family:arial,verdana,sans-serif;
                }
                </style>
			<body>
				$message<br />
				<a href=$url>$delayTime 秒后页面将自动跳转，您也可以点击这里直接跳转。</a>
			</body>
			</html>
			");
		}

		exit;
	}
}
